﻿@{
    ViewBag.Title = "Ban quản trị - Phân quyền";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

@section JavaScriptCSSImport{
    <link href="@Url.Content("~/Content/mycontent/list_counter.css")" rel="stylesheet" type="text/css"/>
    <style>
        .child-opener-image
        {
            cursor: pointer;
        }
        .child-opener-image-column
        {
            text-align: center;
        }
        .jtable-dialog-form
        {
            min-width: 220px;
        }
        .jtable-dialog-form input[type="text"]
        {
            min-width: 200px;
        }
    </style>
}

@section JavaScriptDocumentReady{
    $('#danhSachDanhMuc').jtable({
            tableId: "tableDanhMuc",
            title: 'Danh sách loại tài khoản',
            pageSize: 10,
            paging: true,
            sorting: true,
           //defaultSorting: 'TenDanhMuc ASC',
            //selecting: true, //Enable selecting
            //multiselect: true, //Allow multiple selecting
            //selectingCheckboxes: true, //Show checkboxes on first column
            //selectOnRowClick: false, //Enable this to only select using checkboxes
            actions: {
                listAction: '/Admin/LayDanhSachLoaiTaiKhoan_PQ',
            },

            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false,
                    sorting: false
                },
                //CHILD TABLE
                danhSachQuyen: {
                    title: '',
                    width: '5%',
                    sorting: false,
                    edit: false,
                    create: false,
                    listClass: 'child-opener-image-column',
                    display: function (studentData) {
                        //Create an image that will be used to open child table
                        var $img = $('<img class="child-opener-image" src="@Url.Content("~/Content/quyen_icon.png")" title="Danh sách quyền" />');
                        //Open child table when user clicks the image
                        $img.click(function () {
                            $('#danhSachDanhMuc').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                     
                                        title: 'Danh sách quyền - ' + studentData.record.TenLoaiTaiKhoan,
                                        actions: {
                                            listAction: '/Admin/DanhSachPhanQuyenCuaLoaiTK?loaiTaiKhoan=' + studentData.record.ID,
                                            deleteAction: '/Admin/XoaPhanQuyen',
                                            createAction: '/Admin/ThemQuyen'
                                        },
                                        fields: {
                                            IDLoaiTaiKhoan: {
                                                type: 'hidden',
                                                defaultValue: studentData.record.ID
                                            },
                                            ID: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            },
                                            IDQuyen: {
                                                title: 'Tên quyền',
                                                create: true,
                                                edit: false,
                                                list: true,
                                                options: "/Admin/DanhSachQuyenOptions?loaiTaiKhoan=" + studentData.record.ID
                                            },
                                            Xoa: {
                                                title: 'Xoá/Phục Hồi',
                                                create: false,
                                                edit: true,
                                                list: true,
                                                sorting: true,
                                                type: 'checkbox',
                                                values: { 'false': 'Hoạt động', 'true': 'Bị xóa' },
                                            }
                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                        });
                        //Return image to show on the person row
                        return $img;
                    }
                },
                TenLoaiTaiKhoan : {
                    title: 'Tên loại tài khoản',
                    width: '25%',
                    create: true,
                    edit: true,
                    list: true,
                    sorting: true,
                },
                Xoa: {
                    title: 'Trạng thái',
                    create: false,
                    edit: true,
                    list: true,
                    sorting: true,
                    type: 'checkbox',
                    values: { 'false': 'Hoạt động', 'true': 'Bị xóa' },
                }
            }
        });

        //Load student list from server
        $('#danhSachDanhMuc').jtable('load');
}

<!-- Container for jTable -->
<div id="danhSachDanhMuc"></div>
